/**
 * 基础菜单 商品管理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/system' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="searchForm" class="user-search">
      <el-form-item label="搜索：">
        <el-input
          size="small"
          v-model="searchForm.chain_no"
          placeholder="兑付链单单号"
        ></el-input>
      </el-form-item>
      <!-- <el-form-item label="">
        <el-input size="small" v-model="formInline.deptNo" placeholder="企业名称"></el-input>
      </el-form-item> -->
      <el-form-item label="">
        <el-select
          size="small"
          v-model="searchForm.principal_status"
          placeholder="还款及手续费"
        >
          <el-option value="全部">全部</el-option>
          <el-option value="待结清">待结清</el-option>
          <el-option value="已结清">已结清</el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          size="small"
          v-model="datetime"
          type="datetimerange"
          :picker-options.sync="pickerOptions"
          range-separator="至"
          start-placeholder="兑付日起"
          end-placeholder="兑付日止"
          value-format="yyyy-MM-dd HH:mm:ss"
          align="right"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-search"
          @click="search"
          >搜索</el-button
        >
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table
      size="small"
      :data="listData"
      highlight-current-row
      v-loading="loading"
      border
      element-loading-text="拼命加载中"
      style="width: 100%"
    >
      <el-table-column align="center" label="链单单号">
        <template slot-scope="scope">
          {{ scope.row.scfpChain.chain_no }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="公司">
        <template slot-scope="scope">
          {{ scope.row.scfpEnterprise.name }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="loan_time" label="兑付时间">
      </el-table-column>
      <el-table-column align="center" prop="repay_time" label="还款时间">
      </el-table-column>
      <el-table-column align="center" label="金额">
        <template slot-scope="scope"> ￥{{ scope.row.money }} </template>
      </el-table-column>
      <el-table-column align="center" label="还款状态">
        <template slot-scope="scope">
          <el-button v-if="scope.row.principal_status != '已还款'" size="mini"
            >去还款</el-button
          >
          <p v-else>已还款</p>
        </template>
      </el-table-column>
      <el-table-column align="center" label="利息">
        <template slot-scope="scope"> ￥{{ scope.row.interest }} </template>
      </el-table-column>
      <el-table-column align="center" label="利息支付">
        <template slot-scope="scope">
          <el-button v-if="scope.row.interest_status != '已支付'" size="mini"
            >去支付</el-button
          >
          <p v-else>已支付</p>
        </template>
      </el-table-column>
      <el-table-column align="center" label="服务费">
        <template slot-scope="scope"> ￥{{ scope.row.service }} </template>
      </el-table-column>
      <el-table-column align="center" label="服务费支付">
        <template slot-scope="scope">
          <el-button v-if="scope.row.service_status != '已支付'" size="mini"
            >去支付</el-button
          >
          <p v-else>已支付</p>
        </template>
      </el-table-column>
      <el-table-column align="center" label="结清所有费用">
        <template slot-scope="scope">
          <el-button
            v-if="
              scope.row.principal_status != '已还款' ||
              scope.row.interest_status != '已支付' ||
              scope.row.service_status != '已支付'
            "
            size="mini"
            >结清</el-button
          >
          <p v-else>已结清</p>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination
      v-bind:child-msg="pageparm"
      @callFather="callFather"
    ></Pagination>
  </div>
</template>

<script>
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '添加',
      editForm: {
        deptId: '',
        deptName: '',
        deptNo: '',
        token: localStorage.getItem('logintoken')
      },
      // rules表单验证
      rules: {
        deptName: [
          { required: true, message: '请输入部门名称', trigger: 'blur' }
        ],
        deptNo: [{ required: true, message: '请输入部门代码', trigger: 'blur' }]
      },
      searchForm: {
        chain_no: null,
        currentPage: 1,
        pageSize: 10,
        enterprise_id: 0,
        principal_status: '',
        loan_time: '',
        loan_query_time: ''
      },
      datetime: '',
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      },

      userId: 77,//用户Id

      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.searchForm.enterprise_id = JSON.parse(localStorage.getItem('userdata')).enterprise_id
    this.getLoanData()
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取兑付记录
    getLoanData() {
      this.$axios.post("/api/loan/search", this.searchForm).then(res => {
        console.log(res.data.data);
        this.listData = res.data.data.list
        this.pageparm.currentPage = res.data.data.pageNum
        this.pageparm.pageSize = res.data.data.pageSize
        this.pageparm.total = res.data.data.total
      }).catch(() => {
        this.$message.error("获取兑付记录失败!!")
      })
    },
    // 分页插件事件
    callFather(parm) {
      this.searchForm.currentPage = parm.currentPage
      this.searchForm.pageSize = parm.pageSize
      this.getLoanData();
    },

    search() {
      console.log(this.datetime);
      if (this.datetime != null && this.datetime != '') {
        this.searchForm.loan_time = this.datetime[0]
        this.searchForm.loan_query_time = this.datetime[1]
      } else {
        this.searchForm.loan_time = ''
        this.searchForm.loan_query_time = ''
      }
      this.getLoanData()
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

 
 